<#import "/spring.ftl" as spring />
<@spring.bind "news" />
<#assign formUrl="addNews.html"/>
<#assign formTitle="Add news"/>
<#if (news.id??)>
	<#assign formUrl="editNews.html"/>
	<#assign formTitle="Edit news"/>
</#if>
<head>
	<link rel="stylesheet" type="text/css" href="${rc.contextPath}/scripts/cleditor/jquery.cleditor.css">
	<script type="text/javascript" src="${rc.contextPath}/scripts/cleditor/jquery.cleditor.min.js"></script>
	<script type="text/javascript">
		jQuery(document).ready(function(){
			var $cle = jQuery("textarea.body").cleditor();
			
			$cle.each(function(){
				this.change(function(){
					var $area = this.$area;
					var val = $area.val();	
					val = jQuery.trim(val);								
					if($area.hasClass('limitedInput')){
						var maxlength = $area.attr("rel");
        				maxlength = parseInt(maxlength);
        				if(val.length>maxlength){
        					$area.val(val.substring(0,maxlength));
        				}
					}else{
						$area.val(val);
					}
					this.updateFrame();
				});
			});
			
			jQuery("textarea.limitedInput").keydown(function(e){
        		if(e.keycode == 8 || e.which == 8) return true;
        		var maxlength = jQuery(this).attr("rel");
        		return jQuery(this).val().length <= parseInt(maxlength);
        	}).change(function(){
        		var maxlength = jQuery(this).attr("rel");
        		maxlength = parseInt(maxlength);
        		var val = jQuery(this).val();
        		if(val.length>maxlength){
        			jQuery(this).val(val.substring(0,maxlength));
        		}
        	});		
		});		
	</script>
	<title>${formTitle}</title>
</head>
<form action="${rc.contextPath}/admin/${formUrl}" method="POST" name="news" enctype="multipart/form-data">	
	
	<p>Title *</p>
	<@spring.formInput path="news.title" attributes="maxlength='255' size='86'"/>
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Intro *</p>
	<@spring.formTextarea path="news.intro" attributes='class="body limitedInput" rel="500" cols="50" rows="5"' />	
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Avatar *</p>
	<input name="avatarFile" id="avatarFile" type="file"/>
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Body *</p>
	<@spring.formTextarea path="news.body" attributes='class="body" cols="80" rows="10"'/>
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Tag (separate by comma)</p>
	<@spring.formInput path="news.tagNames" attributes="maxlength='255' size='86'"/>
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Public *</p>
	<input type="checkbox" name="public" ${news.public?string("checked='checked'","")}/>	
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Keywords</p>
	<@spring.formTextarea path="news.keywords" attributes='class="limitedInput" rel="500" cols="40" rows="5"'/>
	<@spring.showErrors "<br>"/>
	<hr/>
	<p>Description</p>
	<@spring.formTextarea path="news.description" attributes='class="limitedInput" rel="500" cols="40" rows="5"'/>
	<@spring.showErrors "<br>"/>
	<hr/>
	<@spring.formHiddenInput path="news.avatar"/>
	<@spring.formHiddenInput path="news.id"/>
	<@spring.formHiddenInput path="news.index"/>
	<@spring.formHiddenInput path="news.commentCount"/>
	<input type="submit" value="Save"/>
</form>